package com.yequan.work;

import java.math.*;

/**
 * @author yequan
 * @date 2021/03/04 14:22
 **/
public class BigDecimalDemo {

    public static void main(String[] args) {
//        distance();
//        scale();
        setDriverPrice();
    }

    public static void setDriverPrice() {
        BigDecimal rideFreeMoney = new BigDecimal("2");
        BigDecimal subtractFree = new BigDecimal("8.4").subtract(rideFreeMoney);
        subtractFree = subtractFree.compareTo(BigDecimal.ZERO) <0 ? BigDecimal.ZERO: subtractFree;
        System.out.println(subtractFree.multiply(new BigDecimal(100)).intValue());
    }

    private static void scale() {
        String slon = "116.53557480581";
        String slat = "39.976174137349";
        slon = new BigDecimal(slon).setScale(6, BigDecimal.ROUND_HALF_UP).toString();
        slat = new BigDecimal(slat).setScale(6, BigDecimal.ROUND_HALF_UP).toString();
        System.out.println(slon + "---" + slat);
    }

    private static void distance() {
        float totalDistance = BigDecimal.valueOf(4659)
                .add(BigDecimal.valueOf(9993))
                .divide(new BigDecimal(1000), 1, BigDecimal.ROUND_HALF_UP).floatValue();
        System.out.println(totalDistance);
        float money = 1.10000038f;
        float v = BigDecimal.valueOf(money).setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
        System.out.println(v);
    }

}
